package com.bookmanage.dao;

import java.sql.*;
import java.util.ArrayList;

import com.bookmanage.user.User;
import com.bookmanage.utils.DBUitls;

public class BookRentConn {
    //用于存Book
    static ArrayList<User> list = new ArrayList<User>();

    public static ArrayList<User> list_return() {

        try {
            Connection conn = DBUitls.getConn();

            String sql = "select * from bookrentifo ";
            //预处理编译sql
            PreparedStatement pst = (PreparedStatement) conn.prepareStatement(sql);
            ResultSet rs = (ResultSet) pst.executeQuery();
            if (conn != null) {
                // System.out.print("success!");
                while (rs.next()) {
                    //从数据库获取书籍信息
                    String user = rs.getString("user");
                    String sex = rs.getString("sex");
                    String grade = rs.getString("grade");
                    String book = rs.getString("book");
                    String start = rs.getString("start");
                    String end = rs.getString("end");
                    //存入到Book类里面
                    User bookrent = new User();
                    bookrent.setBook(book);
                    bookrent.setStart(start);
                    bookrent.setEnd(end);
                    bookrent.setGrade(grade);
                    bookrent.setUser(user);
                    bookrent.setSex(sex);
                    list.add(bookrent);


                }

            } else {
                System.out.println("数据库连接失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //将list返回，方便jsp界面调用
        return list;
    }

}
